package com.boot.main.controller;


import com.boot.main.entity.CcomRole;
import com.boot.main.entity.CcomRoleMenu;
import com.boot.main.entity.CcomRolePermission;
import com.boot.main.service.IRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;

@Slf4j
@RestController
@RequestMapping("/v1/api")
@Api(tags = "角色模块")
public class RoleController {
    @Resource
    private IRoleService roleService;

    @RequestMapping(value="/roles", method = RequestMethod.GET)
    @ApiOperation(value = "获取角色列表")
    public Object getRoles(@RequestParam("page") Integer page,@RequestParam("limit") Integer limit, @RequestParam("name") String name){
        return roleService.getRoles(page, limit, name);
    }

    @RequestMapping(value="/role", method = RequestMethod.POST)
    @ApiOperation(value = "保存角色")
    public Object saveRole(@RequestBody CcomRole role){
        role.setCreate_time(new Date().getTime());
        return roleService.saveRole(role);
    }

    @RequestMapping(value="/role/{id}", method = RequestMethod.PUT)
    @ApiOperation(value="更新角色")
    public Object updateRole(@RequestBody CcomRole role){
        role.setCreate_time(new Date().getTime());
        return roleService.updateRole(role);
    }

    @RequestMapping(value="/role/{id}", method = RequestMethod.DELETE)
    @ApiOperation(value="删除角色")
    public Object deleteRole(@PathVariable long id){
        return roleService.deleteRole(id);
    }

    @RequestMapping(value="/roles/all", method = RequestMethod.GET)
    @ApiOperation(value="获取全部角色")
    public Object getAllRoles(){
        return roleService.getAllRoles();
    }

    @RequestMapping(value="/role/menu/save", method = RequestMethod.POST)
    @ApiOperation(value="保存角色菜单")
    public Object saveRoleMenu(@RequestBody CcomRoleMenu roleMenu){
        roleMenu.setCreate_time(new Date().getTime());
        return roleService.saveRoleMenu(roleMenu);
    }

    @RequestMapping(value="/role/permission/save", method = RequestMethod.POST)
    @ApiOperation(value="保存角色权限")
    public Object saveRolePermission(@RequestBody CcomRolePermission rolePermission){
        rolePermission.setCreate_time(new Date().getTime());
        return roleService.saveRolePermission(rolePermission);
    }
}
